package com.boarsoft.boar.lib.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import com.boarsoft.bean.ReplyInfo;
import com.boarsoft.boar.entity.LibInfo;
import com.boarsoft.boar.lib.LibBiz;
import com.boarsoft.common.Authorized;
import com.boarsoft.common.dao.PagedResult;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/**
 * 
 * @author Mac_J
 *
 */
public abstract class LibAction {
	@Autowired
	protected LibBiz libBiz;

	/**
	 * 按应用ID分页查询所有的组件/服务<br/>
	 * 组件/服务只能位于某个应用下
	 * 
	 * @return
	 */
	@JsonIgnoreProperties({ "apps" })
	@RequestMapping("/list.do")
	@Authorized(code = "lib.list")
	public ReplyInfo<Object> list(String projId, String key, String orderBy, int pageNo, int pageSize) {
		PagedResult<LibInfo> pr = libBiz.list(projId, key, orderBy, pageNo, pageSize);
		return new ReplyInfo<Object>(true, pr);
	}

	@RequestMapping("/remove.do")
	@Authorized(code = "lib.remove")
	public ReplyInfo<Object> remove(String appId, String libId) {
		libBiz.remove(appId, libId);
		return ReplyInfo.SUCCESS;
	}

	@JsonIgnoreProperties({ "apps" })
	@RequestMapping("/get.do")
	@Authorized(code = "lib.get")
	public ReplyInfo<Object> get(String id) {
		LibInfo o = libBiz.get(id);
		return new ReplyInfo<Object>(true, o);
	}

	/**
	 * 仅当不用树管理时使用
	 * 
	 * @return
	 */
	@RequestMapping("/delete.do")
	@Authorized(code = "lib.delete")
	public ReplyInfo<Object> delete(String id) {
		libBiz.delete(id);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/start.do")
	@Authorized(code = "lib.start")
	public ReplyInfo<Object> start(String ids) {
		libBiz.start(ids);
		return ReplyInfo.SUCCESS;
	}

	@RequestMapping("/stop.do")
	@Authorized(code = "lib.stop")
	public ReplyInfo<Object> stop(String ids) {
		libBiz.stop(ids);
		return ReplyInfo.SUCCESS;
	}
}